package cn.tedu.jdbc;
/**
 * JDBC执行查询语句[DQL];
 * 查询所有用户的用户名、密码、年龄;
 * SELECT username, password, age FROM userinfo
 */
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

//[DQL]
public class JDBCDemo5 {
    public static void main(String[] args) {
        try(Connection connection=DBUtil.getConnection();){
            Statement statement = connection.createStatement();
            String sql="SELECT username,password,age FROM userinfo";
            ResultSet r = statement.executeQuery(sql);
            while(r.next()){
                String username=r.getString("username");
                String password=r.getString("password");
                int age=r.getInt("age");
                System.out.println(username+"-"+password+"-"+age);
            }
        }catch (SQLException e){
            throw new RuntimeException(e);
        }

    }
}